home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Doco ƒ / CSMP ƒ / CSMP-V1-083.TXT < prev    next >
Encoding:
Text File  |  1992-06-30  |  53.7 KB  |  1,453 lines

  1. C.S.M.P. Digest             Sat, 16 May 92       Volume 1 : Issue 83
  2.  
  3. Today's Topics:
  4.  
  5.     What does SerSetBuf actually do?
  6.     THINK C and UNIX stat() function
  7.     How to turn File Sharing on?
  8.     Mapping one color to another - help!
  9.     refreshing a colour screen
  10.     How to Get the Name of A File?
  11.     Register variables in Think C 4.05
  12.     Problem De-allocating Memory in variable sized arrays
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  16.  
  17. These digests are available (by using FTP, account anonymous, your email
  18. address as password) in the pub/mac/csmp-digest directory on ftp.cs.uoregon.
  19. edu.  This is also the home of the comp.sys.mac.programmer Frequently Asked
  20. Questions list.  The last several issues of the digest are available from
  21. sumex-aim.stanford.edu as well.
  22.  
  23. These digests are also available via email.  Just send a note saying that you
  24. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  25. automatically receive each new digest as it is created.
  26.  
  27. The digest is a collection of articles from the internet newsgroup comp.sys.
  28. mac.programmer.  It is designed for people who read c.s.m.p. semi-regularly
  29. and want an archive of the discussions.  If you don't know what a newsgroup
  30. is, you probably don't have access to it.  Ask your systems administrator(s)
  31. for details.  (This means you can't post questions to the digest.)
  32.  
  33. The articles in these digests are taken directly from comp.sys.mac.programmer.
  34. They are not edited; all articles included in this digest are in their original
  35. posted form.  The only articles that are -not- included in these digests are
  36. those which didn't receive any replies (except those that give information
  37. rather than ask a question).  All replies to each article are concatenated
  38. onto the original article in the order in which they were received.  Article
  39. threads are not added to the digests until the last article added to the
  40. thread is at least one month old (this is to ensure that the thread is dead
  41. before adding it to the digests).
  42.  
  43. Send administrative mail to mkelly@cs.uoregon.edu.
  44.  
  45. -------------------------------------------------------
  46.  
  47. From: mvivino@helix.nih.gov (Mark A. Vivino)
  48. Subject: What does SerSetBuf actually do?
  49. Date: 9 Apr 92 13:15:04 GMT
  50. Organization: National Institutes of Health
  51.  
  52. I understand how to use SerSetBuf, but I am a bit confused as to how data
  53. actually transfers to the buffer after you make the call. For
  54. example, when I make the call:
  55.  
  56.   SerialErr := SerSetBuf(SPInputRefNum, Ptr(InputbufP), BigBufferSize);
  57.  
  58. I would assume that data starts tranfering out of the default 64 character 
  59. hardware buffer and into the base adress of my Inputbuffer by using
  60. some sort of interrupt mechanism. I obviously do not make any calls
  61. to copy the data into my software created buffer, but the data gets
  62. to the buffer without any trouble. The actual tranfer mechanism
  63. is not discussed in IM, or I haven't seen it. If it is interrupts, then
  64. when do they occur?
  65.  
  66. Not extremely important, but it's nice to know what goes on.
  67.  
  68. Mark Vivino
  69. mvivino@helix.nih.gov
  70.  
  71. +++++++++++++++++++++++++++
  72.  
  73. From: d88-jwa@hemul.nada.kth.se (Jon W{tte)
  74. Date: 9 Apr 92 20:34:30 GMT
  75. Organization: Royal Institute of Technology, Stockholm, Sweden
  76.  
  77. .nih.gov> mvivino@helix.nih.gov (Mark A. Vivino) writes:
  78.  
  79.    I understand how to use SerSetBuf, but I am a bit confused as to how data
  80.    actually transfers to the buffer after you make the call. For
  81.    example, when I make the call:
  82.  
  83.      SerialErr := SerSetBuf(SPInputRefNum, Ptr(InputbufP), BigBufferSize);
  84.  
  85.    I would assume that data starts tranfering out of the default 64 character 
  86.    hardware buffer and into the base adress of my Inputbuffer by using
  87.    some sort of interrupt mechanism. I obviously do not make any calls
  88.    to copy the data into my software created buffer, but the data gets
  89.    to the buffer without any trouble. The actual tranfer mechanism
  90.    is not discussed in IM, or I haven't seen it. If it is interrupts, then
  91.    when do they occur?
  92.  
  93. Why should you look at the serial ports internal buffer.
  94. For all you know, the data there is XOR-ed with a large prime number...
  95. You get at the data using FSRead and FSWrite.
  96.  
  97. Anyway, yes, the serial port chip generates an interrupt when it
  98. receives characters. Exactly when and how is hard to tell, since
  99. the circuitry changes between models. The IIfx and Q900 even have
  100. a separate CPU handling the serial ports !
  101.  
  102. - -- 
  103. h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  104.  
  105. +++++++++++++++++++++++++++
  106.  
  107. From: jmunkki@hila.hut.fi (Juri Munkki)
  108. Date: 12 Apr 92 08:45:05 GMT
  109. Organization: Helsinki University of Technology, Finland
  110.  
  111. In article <1992Apr9.131504.19339@alw.nih.gov> mvivino@helix.nih.gov (Mark A. Vivino) writes:
  112. >I understand how to use SerSetBuf, but I am a bit confused as to how data
  113. >actually transfers to the buffer after you make the call. For
  114. >example, when I make the call:
  115. >
  116. >  SerialErr := SerSetBuf(SPInputRefNum, Ptr(InputbufP), BigBufferSize);
  117. >
  118. >I would assume that data starts tranfering out of the default 64 character 
  119. >hardware buffer and into the base adress of my Inputbuffer by using
  120. >some sort of interrupt mechanism. I obviously do not make any calls
  121. >to copy the data into my software created buffer, but the data gets
  122. >to the buffer without any trouble. The actual tranfer mechanism
  123.  
  124. Most Macs have a 3 character hardware buffer. The IIfx might have something
  125. better, since it has a 6502 controlling the serial port.
  126.  
  127. The default 64 byte serial buffer is a software buffer and SerSetBuf exists
  128. so that you can have something bigger than that. The terminal program that
  129. I'm using right now allows you to set this buffer size and I've found that
  130. I never have problems when I use a 16KB buffer.
  131.  
  132. After you set the buffer, you no longer have to worry about it. Use _Read
  133. calls to read the data. There's no way to tell how the buffer is used, if
  134. it is used at all. All you know is that once you give the buffer to the
  135. serial driver, it has a better chance of not dropping characters.
  136.  
  137. The serial port chip generates an interrupt when it has incoming data. This
  138. is when the characters are copied into the buffer. Don't worry about it.
  139.  
  140.    ____________________________________________________________________________
  141.   / Juri Munkki        /  Helsinki University of Technology   /  Wind  / Project /
  142.  / jmunkki@hut.fi  /  Computing Center Macintosh Support  /  Surf  / Arashi  /
  143.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144.  
  145. +++++++++++++++++++++++++++
  146.  
  147. From: oueichek@imag.fr (Ibaa Oueichek)
  148. Date: 15 Apr 92 12:43:36 GMT
  149.  
  150. d88-jwa@hemul.nada.kth.se (Jon W{tte) writes:
  151. : .nih.gov> mvivino@helix.nih.gov (Mark A. Vivino) writes:
  152. :    I understand how to use SerSetBuf, but I am a bit confused as to how data
  153. :    actually transfers to the buffer after you make the call. For
  154. :    example, when I make the call:
  155. :      SerialErr := SerSetBuf(SPInputRefNum, Ptr(InputbufP), BigBufferSize);
  156. :    I would assume that data starts tranfering out of the default 64 character 
  157. :    hardware buffer and into the base adress of my Inputbuffer by using
  158. :    some sort of interrupt mechanism. I obviously do not make any calls
  159. :    to copy the data into my software created buffer, but the data gets
  160. :    to the buffer without any trouble. The actual tranfer mechanism
  161. :    is not discussed in IM, or I haven't seen it. If it is interrupts, then
  162. :    when do they occur?
  163. : Why should you look at the serial ports internal buffer.
  164. : For all you know, the data there is XOR-ed with a large prime number...
  165. : You get at the data using FSRead and FSWrite.
  166. : Anyway, yes, the serial port chip generates an interrupt when it
  167. : receives characters. Exactly when and how is hard to tell, since
  168. : the circuitry changes between models. The IIfx and Q900 even have
  169. : a separate CPU handling the serial ports !
  170.   I've had the oppurtunity to write a driver for the Z8530, this is the
  171.   Serial Communications Controller used in the Mac (SCC). The serial
  172.   IO drivers in the Mac provide Asynchronous communications, that means
  173.   that the interrupts are generated once there is a character in the
  174.   SCC input register (reciever). BTW, the "hardware" buffer is NOT 64
  175.   characters wide, it's 3 or 4 chars max. The 64 chars buffer is the
  176.   standard buffer allocated by the system at the bootstrap. SerSetBuf
  177.   just changes the pointers, that's why you don't have to worry about
  178.   it. But pay attention about what you are doing, a big buffer can
  179.   resist better against the overflows, but on the other side, you
  180.   may recieve too many chars before you "notice" that you don't need
  181.   them.
  182.  
  183.   I don't know about the IIfx and Q900, but normally when a separate
  184.   CPU handles the serial communications, it doesn't change the
  185.   interrupt moment (ie, there will always be an interrupt when the
  186.   SCC has "matched" a character on the input serial line). It's
  187.   not the CPU which is interrupted anymore but rather the auxiliary
  188.   CPU. The aux CPU informes the main CPU using shared variables. 
  189.  
  190. : -- 
  191. : h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  192. - -- 
  193. Sham(u) ya tha (s)seif(u) lam yaghib(i) | Ibaa Oueichek. oueichek@imag.imag.fr
  194.     Ya jamal(al) majd(i) fi(l) kutub(i) | LABORATOIRE     BULL-IMAG
  195. Kablak(i) (t)tareekh(u) fi thulmaten    | Grenoble. 
  196.     Baadak(i) staula ala (sh)shuhub(i)  |
  197.  
  198. ---------------------------
  199.  
  200. From: bill@lhotse.ucar.edu
  201. Subject: THINK C and UNIX stat() function
  202. Date: 10 Apr 92 16:09:04 GMT
  203. Organization: High Altitude Observatory/NCAR, Boulder CO
  204.  
  205. Does THINK C have an equivalent to the UNIX system library routine stat()?
  206. Basically, I need to determine the time a file was modified so I don't
  207. really need the full functionality of the UNIX stat() routine.  Is there
  208. anything in the THINK C library, or perhaps the Mac toolbox that will
  209. provide this capability?
  210.  
  211. Thanks in advance,
  212. - --Bill
  213.  
  214. +++++++++++++++++++++++++++
  215.  
  216. From: e-sink@uiuc.edu (Eric W. Sink)
  217. Organization: University of Illinois at Urbana-Champaign
  218. Date: Fri, 10 Apr 1992 20:50:30 GMT
  219.  
  220. In <1992Apr10.160904.14885@ncar.ucar.edu> bill@lhotse.ucar.edu writes:
  221.  
  222. >Basically, I need to determine the time a file was modified...
  223.  
  224. unsigned long
  225. GetFModDate(char *filename, short volrefnum, long dirID)
  226. {
  227.     HFileParam                      k;
  228.     Str255                          nm;
  229.     OSErr                           bad;
  230.     strcpy((char *) nm, filename);
  231.     c2pstr(nm);
  232.     k.ioCompletion = NULL;
  233.     k.ioNamePtr = nm;
  234.     k.ioVRefNum = volrefnum;
  235.     k.ioFDirIndex = 0;
  236.     k.ioDirID = dirID;
  237.     bad = PBHGetFInfo((HParmBlkPtr) & k, false);
  238.     if (!bad)
  239.         return k.ioFlMdDat;
  240.     else
  241.         return 0;
  242. }
  243.  
  244.  
  245. - -- 
  246. Eric W. Sink,  Spatial Analysis and Systems Team
  247. USACERL, P.O. Box 9005, Champaign, IL 61826-9005
  248. 1-800-USA-CERL x449,   e-sink@uiuc.edu
  249.  
  250. +++++++++++++++++++++++++++
  251.  
  252. From: roy@adeptsln.cts.com
  253. Date: 14 Apr 92 03:29:09 GMT
  254. Organization: Adept Solutions
  255.  
  256. In article <1992Apr10.160904.14885@ncar.ucar.edu> bill@lhotse.ucar.edu writes:
  257. > Does THINK C have an equivalent to the UNIX system library routine stat()?
  258. > Basically, I need to determine the time a file was modified so I don't
  259. > really need the full functionality of the UNIX stat() routine.  Is there
  260. > anything in the THINK C library, or perhaps the Mac toolbox that will
  261. > provide this capability?
  262. > Thanks in advance,
  263. > --Bill
  264.  
  265. Look in IM Vol II, under PBGetFInfo (page 115), this call gives you everything  
  266. pertenant about the file, including creation & modification dates.
  267.  
  268. - -- 
  269. Roy Lovejoy      | internet:  roy@adeptsln.cts.com
  270. Head RGB Guy     | AppleLink: adept
  271. Adept Solutions  | CIS:       72447,1447
  272. .................| dual certified developer: NeXT & Apple ;)
  273.  
  274. ---------------------------
  275.  
  276. From: casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  277. Subject: How to turn File Sharing on?
  278. Date: 10 Apr 92 17:58:11 GMT
  279. Organization: Universite de Montreal
  280.  
  281.  
  282.     I would like to know how to turn file sharing ON or OFF, not by
  283. using the Control Panel, but from within an application.
  284.     There seems to be no mention of this in IM VI.
  285.  
  286.     Examples in Pascal would be appreciated, but I have a reading
  287. knowledge of C.
  288.  
  289.     Thanks in advance,
  290.     Philippe Casgrain
  291.     Casgrain@ERE.UMontreal.CA
  292.  
  293. +++++++++++++++++++++++++++
  294.  
  295. From: d88-jwa@byse.nada.kth.se (Jon W{tte)
  296. Date: 10 Apr 92 23:26:21 GMT
  297. Organization: Royal Institute of Technology, Stockholm, Sweden
  298.  
  299. .umontreal.ca> casgrain@ERE.UMontreal.CA (Casgrain Philippe) writes:
  300.  
  301.        I would like to know how to turn file sharing ON or OFF, not by
  302.    using the Control Panel, but from within an application.
  303.        There seems to be no mention of this in IM VI.
  304.  
  305. OFF: Send a quit apple event to the File Sharing process.
  306. ON: LaunchApplication on the File Sharing extension.
  307.  
  308. FindFolder, PBCatSearch, GetNextProcess, GetProcessInfo and the
  309. AE manager seems to be the parts you need.
  310.  
  311. - -- 
  312. h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  313.  
  314. +++++++++++++++++++++++++++
  315.  
  316. From: lkimes@alshain.usc.edu (Lance 'Moof' Kimes)
  317. Date: 10 Apr 1992 19:23:15 -0700
  318. Organization: University of Southern California, Los Angeles, CA
  319.  
  320.  
  321. In article <D88-JWA.92Apr11002621@byse.nada.kth.se>, d88-jwa@byse.nada.kth.se (Jon W{tte) writes:
  322. |> .umontreal.ca> casgrain@ERE.UMontreal.CA (Casgrain Philippe) writes:
  323. |> 
  324. |>        I would like to know how to turn file sharing ON or OFF, not by
  325. |>    using the Control Panel, but from within an application.
  326. |>        There seems to be no mention of this in IM VI.
  327. |> 
  328. |> OFF: Send a quit apple event to the File Sharing process.
  329. |> ON: LaunchApplication on the File Sharing extension.
  330. |> 
  331. |> FindFolder, PBCatSearch, GetNextProcess, GetProcessInfo and the
  332. |> AE manager seems to be the parts you need.
  333. |> 
  334. |> -- 
  335. |> h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  336.  
  337.  
  338. Have you tried this to see if it works? It seems to me to be both very useful &
  339. full of potential security hazards.
  340.  
  341. I know all users should be setup already with names & passwords, but what about hte clueless who are not? Even if everythings passworded, sharing could be turned on AGAINST your wishes & compromised passwords then allow easy entry.
  342.  
  343.  
  344. I guess we're just paranoid at USC, but we're safe. :-)
  345.  
  346. Lance Kimes
  347. USC
  348.  
  349. +++++++++++++++++++++++++++
  350.  
  351. From: lsr@taligent.com (Larry Rosenstein)
  352. Date: 13 Apr 92 18:32:22 GMT
  353. Organization: Taligent, Inc.
  354.  
  355. In article <1992Apr10.175811.7669@cc.umontreal.ca>, casgrain@ERE.UMontreal.CA
  356. (Casgrain Philippe) writes:
  357. >     I would like to know how to turn file sharing ON or OFF, not by
  358. > using the Control Panel, but from within an application.
  359.  
  360. See Tech Note 305.
  361. - --
  362. Larry Rosenstein
  363. Taligent, Inc.
  364. lsr@taligent.com
  365.  
  366.  
  367. +++++++++++++++++++++++++++
  368.  
  369. From: roy@adeptsln.cts.com
  370. Date: 14 Apr 92 03:37:29 GMT
  371. Organization: Adept Solutions
  372.  
  373. In article <kucjcjINN4jl@alshain.usc.edu> lkimes@alshain.usc.edu (Lance 'Moof'  
  374. Kimes) writes:
  375. > In article <D88-JWA.92Apr11002621@byse.nada.kth.se>, d88-jwa@byse.nada.kth.se  
  376. (Jon W{tte) writes:
  377. > |> .umontreal.ca> casgrain@ERE.UMontreal.CA (Casgrain Philippe) writes:
  378. > |> 
  379. > |>        I would like to know how to turn file sharing ON or OFF, not by
  380. > |>    using the Control Panel, but from within an application.
  381. > |>        There seems to be no mention of this in IM VI.
  382. > |> 
  383. > |> OFF: Send a quit apple event to the File Sharing process.
  384. > |> ON: LaunchApplication on the File Sharing extension.
  385. > |> 
  386. > |> FindFolder, PBCatSearch, GetNextProcess, GetProcessInfo and the
  387. > |> AE manager seems to be the parts you need.
  388. > |> 
  389. > |> -- 
  390. > |> h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  391. > Have you tried this to see if it works? It seems to me to be both very useful  
  392. &
  393. > full of potential security hazards.
  394. > I know all users should be setup already with names & passwords, but what  
  395. about hte clueless who are not? Even if everythings passworded, sharing could  
  396. be turned on AGAINST your wishes & compromised passwords then allow easy entry.
  397. > I guess we're just paranoid at USC, but we're safe. :-)
  398. > Lance Kimes
  399. > USC
  400.  
  401. What security hazard? The Apple Event is being sent FROM THE SAME MACHINE that  
  402. filesharing is on. (Program sharing has it's own password setup). Sharing isn't  
  403. being turned on against YOUR wishes because YOU are on the machine! Unless you  
  404. are paranoid about turning it on, yourself. It's just an alternate way, other  
  405. than the Control Panel.
  406.  
  407. Lance, maybe you can specify what you are paranoid about, because it seems  
  408. completely tame.
  409. - -- 
  410. Roy Lovejoy      | internet:  roy@adeptsln.cts.com
  411. Head RGB Guy     | AppleLink: adept
  412. Adept Solutions  | CIS:       72447,1447
  413. .................| dual certified developer: NeXT & Apple ;)
  414.  
  415. ---------------------------
  416.  
  417. From: krk@itl.itd.umich.edu (Kenneth Knight)
  418. Subject: Mapping one color to another - help!
  419. Organization: Instructional Technology Laboratory, University of Michigan
  420. Date: Tue, 14 Apr 92 12:08:24 GMT
  421.  
  422. I need some more help....
  423.  
  424. I am writing a image processing tool that will re-map one color to another.
  425. Specifically, all the pixels in an image (32 bit deep GWorld) of the specified
  426. color will have their color changed to the current foreground color. I thought
  427. that using the SetEntries() toolbox call to modify the 32-bit deep GWorld's
  428. CLUT would make sense, but I can not figure out where the current color, the
  429. one that will be changed, is in the CLUT. Nor am I sure just what goes in
  430. the CSpecArray.value field. 
  431.  
  432. IM V says that SetEntries only works with 16-bit value integers and this also
  433. strikes me as wrong since that would limit a CLUT to 128k worth of colors and
  434. in a 32-bit deep GWorld we have many more than that.
  435.  
  436. How do I perform this color re-mapping?
  437.  
  438. Thanks
  439.  
  440.   ** Ken **
  441. krk@itl.itd.umich.edu
  442.  
  443. +++++++++++++++++++++++++++
  444.  
  445. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  446. Organization: Kalamazoo College
  447. Date: Tue, 14 Apr 1992 13:06:08 GMT
  448.  
  449. krk@itl.itd.umich.edu (Kenneth Knight) writes:
  450. >
  451. >...all the pixels in an image (32 bit deep GWorld) of the specified
  452. >color will have their color changed to the current foreground color. I thought
  453. >that using the SetEntries() toolbox call to modify the 32-bit deep GWorld's
  454. >CLUT would make sense, but I can not figure out where the current color, the
  455. >one that will be changed, is in the CLUT.
  456.  
  457. A 32-bit-deep graphics image stores the color values directly, and
  458. doesn't need a color lookup table.  I'll bet there isn't a CLUT there,
  459. or if there is, changing it probably won't do you any good.
  460. Try checking out (**GetGWorldDevice(yourGWorld)).gdType.  CLUT devices
  461. return 0;  yours should be 2.  Read the chapter on Graphics Devices for
  462. more info (IM6's is better than IM5's, it talks about GWorlds).
  463.  
  464. You'll probably want to just scan through the data a longword at a time,
  465. reading in a pixel and changing it if it matches the proper color.
  466. - -- 
  467.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  468.  Ceci n'est pas une .signature.
  469.  
  470. +++++++++++++++++++++++++++
  471.  
  472. From: russotto@eng.umd.edu (Matthew T. Russotto)
  473. Date: Tue, 14 Apr 92 15:21:06 GMT
  474. Organization: College of Engineering, University of Maryland, College Park
  475.  
  476. In article <1992Apr14.120824.12158@terminator.cc.umich.edu> krk@itl.itd.umich.edu (Kenneth Knight) writes:
  477. >I need some more help....
  478. >
  479. >I am writing a image processing tool that will re-map one color to another.
  480. >Specifically, all the pixels in an image (32 bit deep GWorld) of the specified
  481. >color will have their color changed to the current foreground color. I thought
  482. >that using the SetEntries() toolbox call to modify the 32-bit deep GWorld's
  483. >CLUT would make sense, but I can not figure out where the current color, the
  484. >one that will be changed, is in the CLUT. Nor am I sure just what goes in
  485. >the CSpecArray.value field. 
  486.  
  487. 32-bit GWorlds do NOT have useful color tables.  They are 'direct
  488. mapped', meaning each pixel value is $aarrggbb, where a = alpha
  489. channel, r = red, g = green, b = blue.  The color table is ignored.
  490. You have to iterate through the values in the pixmap and actually
  491. change the pixel values.
  492.  
  493.  
  494.  
  495. - -- 
  496. Matthew T. Russotto    russotto@eng.umd.edu    russotto@wam.umd.edu
  497. Some news readers expect "Disclaimer:" here.
  498. Just say NO to police searches and seizures.  Make them use force.
  499. (not responsible for bodily harm resulting from following above advice)
  500.  
  501. +++++++++++++++++++++++++++
  502.  
  503. From: krk@itl.itd.umich.edu (Kenneth Knight)
  504. Date: 15 Apr 92 17:01:59 GMT
  505. Organization: Instructional Technology Laboratory, University of Michigan
  506.  
  507. In article <1992Apr14.152106.5674@eng.umd.edu> russotto@eng.umd.edu (Matthew T. Russotto) writes:
  508. >In article <1992Apr14.120824.12158@terminator.cc.umich.edu> krk@itl.itd.umich.edu (Kenneth Knight) writes:
  509. >>I need some more help....
  510. >>
  511. >>I am writing a image processing tool that will re-map one color to another.
  512. >>Specifically, all the pixels in an image (32 bit deep GWorld) of the specified
  513. >>color will have their color changed to the current foreground color. I thought
  514. >>that using the SetEntries() toolbox call to modify the 32-bit deep GWorld's
  515. >>CLUT would make sense, but I can not figure out where the current color, the
  516. >>one that will be changed, is in the CLUT. Nor am I sure just what goes in
  517. >>the CSpecArray.value field. 
  518. >
  519. >32-bit GWorlds do NOT have useful color tables.  They are 'direct
  520. >mapped', meaning each pixel value is $aarrggbb, where a = alpha
  521. >channel, r = red, g = green, b = blue.  The color table is ignored.
  522. >You have to iterate through the values in the pixmap and actually
  523. >change the pixel values.
  524.  
  525. Alright, as an aside. I managed to do what I needed with a costum
  526. search proc (and the documentation on those is really wierd. I am
  527. not quite sure what the result param is for...). I followed a 
  528. standard one I found and it works, but it only works for GWorld's
  529. that are 32 bits deep. I applied it to the same GWorld set to 8
  530. bits deep and nothing happened. 
  531.  
  532. Ideas anyone?
  533.  
  534. (Hey, Matthew, nice to see you are still around. Tell
  535. everyone else I am too....and it might be that the U.M. cops
  536. would get along with you EVEN BETTER than UMCP's...)
  537.  
  538. ---------------------------
  539.  
  540. From: cmp9116@sys.uea.ac.uk (A. Coats)
  541. Subject: refreshing a colour screen
  542. Date: 14 Apr 92 12:34:30 GMT
  543.  
  544. Pleae could someone help me on the subject of refreshing a screen
  545. after it has been overwritten when a dialog box has been displayed.
  546. I have no representation of what is on the screen, so redrawing it is
  547. a long process.  I have tried bitmaps, pixmaps, and offscreen drawing
  548. (using Apples Tech. note 120, but falls over on the For loop, and messes
  549. up the colour).  If anyone could tell me how to copy the screen pixels
  550. to a pixel map, and then copying it back again with the colour info.
  551. intact.
  552.  
  553. Thanks in advance.
  554.  
  555. David, via Andy, UEA - Norwich.
  556.  
  557. +++++++++++++++++++++++++++
  558.  
  559. From: krk@itl.itd.umich.edu (Kenneth Knight)
  560. Date: 15 Apr 92 17:34:59 GMT
  561. Organization: Instructional Technology Laboratory, University of Michigan
  562.  
  563. In article <cmp9116.703254870@s1.sys.uea.ac.uk> you write:
  564. >Pleae could someone help me on the subject of refreshing a screen
  565. >after it has been overwritten when a dialog box has been displayed.
  566. >I have no representation of what is on the screen, so redrawing it is
  567. >a long process.  I have tried bitmaps, pixmaps, and offscreen drawing
  568. >(using Apples Tech. note 120, but falls over on the For loop, and messes
  569. >up the colour).  If anyone could tell me how to copy the screen pixels
  570. >to a pixel map, and then copying it back again with the colour info.
  571. >intact.
  572.  
  573. Very quickly. You will generaly do all drawing to a screen in one routine -
  574. the routine that is called when an update event takes place. Up to that point
  575. most times you will do your drawing in an offscreen graphic's world or repre-
  576. sent it with some meta-language or some other mains depending on what you
  577. deem best. In order to get the udpate events you have to invalidate the
  578. rectangle (or region) that needs to be re-drawn. For simplicities sake just
  579. invalidate the whole portRect of the window (I assume that is what you
  580. have) that got covered by the dialog (naturally, it is better just to
  581. invalidate the part that needs to be re-drawn). The call you need for this
  582. is InvalRect().
  583.  
  584. Let's assume you are doing all your drawing to an 8-bit deep off screen
  585. GWorld that you've made with NewGWorld (IM VI and note 120, and other
  586. places). You've been very good about being sure to draw into that world
  587. (i.e. Get/Set-GWorld calls in the right places and you do Lock/Unlock-Pixles()
  588. calls before and after you do any drawing into this GWorld as you should).
  589.  
  590. To draw that GWorld to the screen you would do something like this (in your
  591. function that handles update events):
  592. if (theWindow /* WindowPtr passed in */ == windowToUpdate) {
  593.    BeginUpdate(theWindow);
  594.      EraseRect(&(theWindow->portRect)); /* clear it all out. */
  595.      DrawControls(theWindow);       /* if you have 'em. */
  596.      DrawGrowIcon(theWindow);      /* ditto */
  597.      CopyBits(&((GrafPtr)drawWorld)->portBits, &((GrafPtr)theWindow)->portBits,
  598.                &(theWindow->portRect), &(theWindow->portRect), srcCopy, nil);
  599.    EndUpdate(theWindow);
  600.  
  601. The CopyBits() is the key call. It copies the offscreen GWorld to you
  602. window. To be perfectly safe you should make sure that the foreground color
  603. is black and background color is white (of the current grafport). This will
  604. let you avoid any potental colorizing problems.
  605.  
  606. Hope this helps (I am in a rush...)...
  607.  
  608. ---------------------------
  609.  
  610. From: kevin@crash.cts.com (Kevin Hill)
  611. Subject: How to Get the Name of A File?
  612. Date: 14 Apr 92 10:42:26 GMT
  613. Organization: Crash TimeSharing, El Cajon, CA
  614.  
  615.  
  616.   I am on the home stretch of my new program!!  BUT!
  617.  
  618.    I am using the class library of THink C
  619.  
  620.    Ok here's the problem:
  621.  
  622.      I have the DirID of the directory.
  623.      I have the volNum of the directory.
  624.      I don't have the name of the file. (problem)
  625.  
  626.   I tried to use GetMacFileInfo to get the Finfo struct that would contain
  627. the name and type etc.. However, I get a -43 error.
  628.  
  629.   Other problem.
  630.     when I use ioFDirIndex to get the files in the directory, I again cannot figure out how
  631.  to get the name of the files in the directory.  GetMacFileInfo again does not
  632. work, it crashes with -43 error. yuk..  any help would be appreciated.
  633.  -Kevin
  634.  
  635. +++++++++++++++++++++++++++
  636.  
  637. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  638. Organization: Kalamazoo College
  639. Date: Tue, 14 Apr 1992 15:18:00 GMT
  640.  
  641. kevin@crash.cts.com (Kevin Hill) writes:
  642. >
  643. >  I am on the home stretch of my new program!!  BUT!
  644. >
  645. >   Ok here's the problem:
  646. >
  647. >     I have the DirID of the directory.
  648. >     I have the volNum of the directory.
  649. >     I don't have the name of the file. (problem)
  650. >
  651. >  I tried to use GetMacFileInfo to get the Finfo struct that would contain
  652. >the name and type etc.. However, I get a -43 error.
  653. >
  654. >when I use ioFDirIndex to get the files in the directory,
  655. >I again cannot figure out how to get the name of the files
  656. >in the directory.  GetMacFileInfo again does not
  657. >work, it crashes with -43 error.
  658.  
  659. I'm not sure I understand.  This is the same problem, right?  If you
  660. have the dirID and volNum, you need one more piece of information to get
  661. at the file, and if you don't know the name, it must be the dirIndex.
  662. So you're trying to use a dirIndex to find your file?
  663.  
  664. CFile::GetMacFileInfo() relies on having the name of the file
  665. set up properly;  it won't help you if you haven't specified the file.
  666.  
  667. Here's a little sample code that cycles through a directory.  I use
  668. GetCatInfo, but the idea's the same.
  669.  
  670. Str63 myName;
  671. OSErr theOSErr;
  672. CInfoPBRec myPB;
  673. myPB.hFileInfo.ioCompletion = NULL;
  674. myPB.hFileInfo.ioNamePtr = myName;
  675. myPB.hFileInfo.ioVRefNum = vRefNum;
  676. myPB.hFileInfo.ioFrIndex = 1;
  677. while (theOSErr == noErr) {
  678.     Boolean isFile;
  679.     myName[0] = 0;
  680.     myPB.hFileInfo.ioDirID = dirID; // see IM4 p126.
  681.     theOSErr = PBGetCatInfo(&myPB, FALSE);
  682.     if (theOSErr == fnfErr || theOSErr == nsvErr) {
  683.         break;
  684.     } else if (theOSErr != noErr) {
  685.         Debugger();
  686.         break;
  687.     }
  688.     isFile = (BitTst(&myPB.dirInfo.ioFlAttrib, 3) == 0);
  689.     if (isFile) {
  690.         FInfo *theFInfo;
  691.         theFInfo = &myPB.hFileInfo.ioFlFndrInfo;
  692.     }
  693.     ++myPB.hFileInfo.ioFDirIndex;
  694. }
  695.  
  696. That call to Debugger() is in there because I don't think any error
  697. should be returned except an fnfErr (which indicates that there are no
  698. more files in the directory) or an nsvErr (which would indicate a bad
  699. vRefNum or dirID).
  700.  
  701. Note that you have to reset dirID each time through.  Contrary to a
  702. comment in the UMPG Volume I, there _is_ a reference to this in IM;
  703. it's just very well hidden.  :-)
  704. - -- 
  705.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  706.  "Almost all portables today employ passive-matrix LCDs, and no one expects
  707.  active-matrix screens to be cost-competitive for a few years" -PC World 2/92
  708.  
  709. +++++++++++++++++++++++++++
  710.  
  711. From: mspace@netcom.com (Brian Hall)
  712. Date: 15 Apr 92 00:22:26 GMT
  713. Organization: Netcom - Online Communication Services  (408 241-9760 guest)
  714.  
  715. In article <1992Apr14.104226.1649@crash.cts.com> kevin@crash.cts.com (Kevin Hill) writes:
  716. >   I am using the class library of THink C
  717. >
  718. >   Ok here's the problem:
  719. >
  720. >     I have the DirID of the directory.
  721. >     I have the volNum of the directory.
  722. >     I don't have the name of the file. (problem)
  723. >
  724. Why not call CDataFile::GetName to get the name?
  725.  
  726.  
  727. - -- 
  728. +-----------------------------------------------------------------------------+
  729. | Brian Hall, Mark/Space Softworks                                            |
  730. | mspace@netcom.com; Applelink, America Online: MarkSpace                     |
  731. +-----------------------------------------------------------------------------+
  732.  
  733. ---------------------------
  734.  
  735. From: erh0362@tesla.njit.edu
  736. Subject: Register variables in Think C 4.05
  737. Date: 14 Apr 92 14:45:12 GMT
  738. Organization: New Jersey Institute of Technology
  739.  
  740.  
  741.     How intelligent is Think C 4.05 about assigning variables to 
  742. registers? Will declaring my frequently used variables as register 
  743. offer significant improvements or should I rely on Think C to do this for 
  744. me?
  745.  
  746.  
  747. Elliotte Rusty Harold        Department of Applied Mathematics
  748. elharo@m.njit.edu        New Jersey Institute of Technology
  749. erh0362@tesla.njit.edu        Newark, NJ 07103
  750.  
  751. +++++++++++++++++++++++++++
  752.  
  753. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  754. Date: 15 Apr 92 14:40:00 GMT
  755. Organization: Symantec Corp.
  756.  
  757. >>>>> On 14 Apr 92 14:45:12 GMT, erh0362@tesla.njit.edu said:
  758.  >     How intelligent is Think C 4.05 about assigning variables to
  759.  > registers? Will declaring my frequently used variables as register
  760.  > offer significant improvements or should I rely on Think C to do
  761.  > this for me?
  762.  
  763. C 4.0.x does *not* do any register allocation. If you want your
  764. locals to be placed in registers, you must declare them with the
  765. register keyword. C 5.0 does support register allocation, however.
  766.  
  767. If you use the register keyword carefully (and probably even not
  768. carefully) in C 4.0, you can get a fair amount of improvement in code
  769. size and most likely code speed.
  770.  
  771.     -phil
  772. - --
  773.    Phil Shapiro                                   Software Engineer
  774.    Language Products Group                     Symantec Corporation
  775.            Internet: phils@cs.brandeis.edu
  776.  
  777. ---------------------------
  778.  
  779. From: umsfjban@bill.oscs.montana.edu (Jeff Banfield)
  780. Subject: Problem De-allocating Memory in variable sized arrays
  781. Date: 1 Apr 92 22:26:46 GMT
  782. Organization: Montana State University, Bozeman  MT
  783.  
  784. I have a problem in de-allocating memory that I have allocated using
  785. NewPtr.  I'm working on some image analysis software so I need to
  786. use some large dynamically allocated arrays.  I'm using a Mac variation
  787. of the approach described in Numerical Recipes in C which basically 
  788. allocates pointers to the rows and then allocates memeory for each row.
  789.  
  790. Everything seems to work fine ... I can allocate the array, I can fill
  791. it up with numbers and I can plot it or numerically manipulate the array.
  792. If I de-allocate the array right after I create it the memory is freed
  793. up just like should be, but if use it, like filling it up wih numbers
  794. then I can't de-allocate it.
  795.  
  796. I'm new to both C and MacIntosh Programming so I may be missing something
  797. obvious.  I've learned more about the heap and the stack over the last 
  798. few days than I ever wanted to know ... but maybe it's not enough.
  799. I'm using Think C 5.0.
  800.  
  801. Here's the code ... this is the most recent incarnation, I've tried
  802. several variations to see if I can solve the problem (I'm typing it
  803. in at the terminal so don't flame me if I forget a ; ...) 
  804. Any suggestions on improving the implementation (yes I know I should
  805. check for succesful allocation) or style are welcome.
  806.  
  807.  
  808. global variables:
  809.  
  810. unsigned char      **DATA;
  811. int        NROW, NCOL;
  812.  
  813. void allocateDATA (void)
  814. {
  815.     register i;
  816.  
  817.     DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  818.     DATA -= 1;    /* to allow indexing starting at 1 */
  819.  
  820.     for (i = 1; i <= NROW; i++){
  821.         DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  822.         DATA[i] -= 1;  /* to allow indexing starting at 1 */
  823.     }
  824. }
  825.  
  826. void freeDATA (void)
  827. {
  828.     register i;
  829.  
  830.     for (i = 1; i <= NROW; i++){
  831.         DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  832.     }
  833.     DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  834. }
  835.  
  836.  
  837.  
  838. If I give the command:
  839.  
  840.     allocateDATA();
  841.  
  842. .... then check the heap size it's gone down the appropriate amount
  843.  
  844. If I now give the command
  845.  
  846.     freeDATA();
  847.  
  848. .... and now check the heap size it's increased the appropriate amount
  849.  
  850. However if I give the commands
  851.  
  852.     allocateDATA();
  853. ... heap size decreases
  854.     fillDATA();
  855. ... which runs through the open file dialog, reads in a file and puts
  856. ... the results into DATA, the heap size doesn't change ... which it's
  857. ... not supposed to do since I've already allocated the memory.
  858.  
  859. Now if I call
  860.     freeDATA();
  861. ... and check the heap size it doesn't change ... it's as though I never
  862. ... freed the data.
  863.  
  864. Any suggestions or comments would be greatly appreciated.
  865.  
  866. Jeff Banfield
  867. umsfjban@bill.oscs.montana.edu
  868.  
  869. +++++++++++++++++++++++++++
  870.  
  871. From: Steve Creps <creps@silver.ucs.indiana.edu>
  872. Organization: Indiana University
  873. Date: Mon, 6 Apr 1992 10:37:35 -0500
  874.  
  875. In article <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  876. >I have a problem in de-allocating memory that I have allocated using
  877. >NewPtr.  I'm working on some image analysis software so I need to
  878.  
  879. >unsigned char      **DATA;
  880. >int        NROW, NCOL;
  881. >
  882. >void allocateDATA (void)
  883. >{
  884. >    register i;
  885. >
  886. >    DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  887. >    DATA -= 1;    /* to allow indexing starting at 1 */
  888. >
  889. >    for (i = 1; i <= NROW; i++){
  890. >        DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  891. >        DATA[i] -= 1;  /* to allow indexing starting at 1 */
  892. >    }
  893. >}
  894. >
  895. >void freeDATA (void)
  896. >{
  897. >    register i;
  898. >
  899. >    for (i = 1; i <= NROW; i++){
  900. >        DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  901. >    }
  902. >    DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  903. >}
  904.  
  905.    First I would ask (not a flame) why you want to start the array indices at
  906. 1 instead of zero?  You said you are new to C, so you may not yet have found
  907. that arrays nearly always start at 0 in C programs.  IMO it's better to start
  908. doing (and getting used to) zero-based arrays sooner than later.
  909.  
  910.    I strongly suspect that your problem has something to do with the way you
  911. are manipulating DATA (e.g. adding and subtracting).  I suggest changing the
  912. program to start the array at zero (remember to change "i <= NROW" to "i <
  913. NROW").  I'm not absolutely sure that that will fix it, but one experiment is
  914. worth a thousand theories.
  915.  
  916.    Anyway, you probably don't want to be incrementing and decrementing
  917. pointers.  This practice often works, but it is not guaranteed that it
  918. always will.  Your mileage may vary, depending on operating system, compiler,
  919. and the data types involved.
  920.  
  921. - -    -    -    -    -    -    -    -    -    -
  922. Steve Creps, Indiana University
  923. creps@silver.ucs.indiana.edu (129.79.1.6)
  924. {inuxc,rutgers,uunet!uiucdcs,pur-ee}!iuvax!silver!creps
  925.  
  926. +++++++++++++++++++++++++++
  927.  
  928. From: sgrenander@nasamail.jpl.nasa.gov (Sven Grenander)
  929. Date: 6 Apr 92 20:47:52 GMT
  930. Organization: Jet Propulsion Laboratory
  931.  
  932. In article <1992Apr6.103745.28462@bronze.ucs.indiana.edu>, Steve Creps <creps@silver.ucs.indiana.edu> writes:
  933. > In article <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  934. > >I have a problem in de-allocating memory that I have allocated using
  935. > >NewPtr.  I'm working on some image analysis software so I need to
  936. > >unsigned char      **DATA;
  937.  
  938.  .........
  939.  
  940. > >
  941. > >    for (i = 1; i <= NROW; i++){
  942. > >        DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  943. > >    }
  944. > >    DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  945. > >}
  946. >    First I would ask (not a flame) why you want to start the array indices at
  947. > 1 instead of zero?  You said you are new to C, so you may not yet have found
  948. > that arrays nearly always start at 0 in C programs.  IMO it's better to start
  949. > doing (and getting used to) zero-based arrays sooner than later.
  950.  
  951. ........
  952.  
  953. The problem with zero-based arrays is that most (?) mathematical routines
  954. have been developed for one-based arrays, but that's just an aside.
  955.  
  956. If you look in "Mathematical Recipes In C" they provide routines
  957. for allocating and freeing arrays. The routines work, I use them (with
  958. minor modifications) but may not represent the best C implementations
  959. as they do things like SHIFT rather than divide by 2 etc.
  960.  
  961. - - Sven
  962.  
  963. +++++++++++++++++++++++++++
  964.  
  965. From: Steve Creps <creps@silver.ucs.indiana.edu>
  966. Organization: Indiana University
  967. Date: Mon, 6 Apr 1992 10:37:35 -0500
  968.  
  969. In article <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  970. >I have a problem in de-allocating memory that I have allocated using
  971. >NewPtr.  I'm working on some image analysis software so I need to
  972.  
  973. >unsigned char      **DATA;
  974. >int        NROW, NCOL;
  975. >
  976. >void allocateDATA (void)
  977. >{
  978. >    register i;
  979. >
  980. >    DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  981. >    DATA -= 1;    /* to allow indexing starting at 1 */
  982. >
  983. >    for (i = 1; i <= NROW; i++){
  984. >        DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  985. >        DATA[i] -= 1;  /* to allow indexing starting at 1 */
  986. >    }
  987. >}
  988. >
  989. >void freeDATA (void)
  990. >{
  991. >    register i;
  992. >
  993. >    for (i = 1; i <= NROW; i++){
  994. >        DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  995. >    }
  996. >    DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  997. >}
  998.  
  999.    First I would ask (not a flame) why you want to start the array indices at
  1000. 1 instead of zero?  You said you are new to C, so you may not yet have found
  1001. that arrays nearly always start at 0 in C programs.  IMO it's better to start
  1002. doing (and getting used to) zero-based arrays sooner than later.
  1003.  
  1004.    I strongly suspect that your problem has something to do with the way you
  1005. are manipulating DATA (e.g. adding and subtracting).  I suggest changing the
  1006. program to start the array at zero (remember to change "i <= NROW" to "i <
  1007. NROW").  I'm not absolutely sure that that will fix it, but one experiment is
  1008. worth a thousand theories.
  1009.  
  1010.    Anyway, you probably don't want to be incrementing and decrementing
  1011. pointers.  This practice often works, but it is not guaranteed that it
  1012. always will.  Your mileage may vary, depending on operating system, compiler,
  1013. and the data types involved.
  1014.  
  1015. - -    -    -    -    -    -    -    -    -    -
  1016. Steve Creps, Indiana University
  1017. creps@silver.ucs.indiana.edu (129.79.1.6)
  1018. {inuxc,rutgers,uunet!uiucdcs,pur-ee}!iuvax!silver!creps
  1019.  
  1020. +++++++++++++++++++++++++++
  1021.  
  1022. From: sgrenander@nasamail.jpl.nasa.gov (Sven Grenander)
  1023. Date: 6 Apr 92 20:47:52 GMT
  1024. Organization: Jet Propulsion Laboratory
  1025.  
  1026. In article <1992Apr6.103745.28462@bronze.ucs.indiana.edu>, Steve Creps <creps@silver.ucs.indiana.edu> writes:
  1027. > In article <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1028. > >I have a problem in de-allocating memory that I have allocated using
  1029. > >NewPtr.  I'm working on some image analysis software so I need to
  1030. > >unsigned char      **DATA;
  1031.  
  1032.  .........
  1033.  
  1034. > >
  1035. > >    for (i = 1; i <= NROW; i++){
  1036. > >        DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  1037. > >    }
  1038. > >    DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  1039. > >}
  1040. >    First I would ask (not a flame) why you want to start the array indices at
  1041. > 1 instead of zero?  You said you are new to C, so you may not yet have found
  1042. > that arrays nearly always start at 0 in C programs.  IMO it's better to start
  1043. > doing (and getting used to) zero-based arrays sooner than later.
  1044.  
  1045. ........
  1046.  
  1047. The problem with zero-based arrays is that most (?) mathematical routines
  1048. have been developed for one-based arrays, but that's just an aside.
  1049.  
  1050. If you look in "Mathematical Recipes In C" they provide routines
  1051. for allocating and freeing arrays. The routines work, I use them (with
  1052. minor modifications) but may not represent the best C implementations
  1053. as they do things like SHIFT rather than divide by 2 etc.
  1054.  
  1055. - - Sven
  1056.  
  1057. +++++++++++++++++++++++++++
  1058.  
  1059. From: d88-jwa@hemul.nada.kth.se (Jon W{tte)
  1060. Date: 8 Apr 92 09:40:29 GMT
  1061. Organization: Royal Institute of Technology, Stockholm, Sweden
  1062.  
  1063. > harlan@copper.ucs.indiana.edu (Pete Harlan) writes:
  1064.  
  1065.    |>unsigned char      **DATA;
  1066.    |>
  1067.    |>    register i;
  1068.    |>
  1069.    |>    DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  1070.  
  1071. DATA is a pointer to NROW pointers to unsigned char.
  1072.  
  1073.    |>    DATA -= 1;    /* to allow indexing starting at 1 */
  1074.  
  1075. DATA is decreased one UNIT; where the unit is "pointer" in
  1076. this case. Use DATA from 1 to NROW now, not 0 to NROW-1
  1077.  
  1078.    |>    for (i = 1; i <= NROW; i++){
  1079.  
  1080. See, he loops from 1 to NROW !
  1081.  
  1082.    |>        DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  1083.  
  1084. Allocate NCOL chars
  1085.  
  1086.    |>        DATA[i] -= 1;  /* to allow indexing starting at 1 */
  1087.  
  1088. Decrease one unit. In this case, the unit is a char. Still OK.
  1089.  
  1090.    This is wrong-o, forget the deallocation, you've stomped on memory
  1091.    already.  Go back to K&R, do not pass GO, an no $200.
  1092.  
  1093. Why ? I see exactly nothing wrong with this.
  1094.  
  1095.    |>    for (i = 1; i <= NROW; i++){
  1096.    |>        DisposPtr(DATA[i] + 1);  /* + 1 because of index starting at 1 */
  1097.    |>    }
  1098.    |>    DisposPtr(DATA + 1);   /* + 1 because of index starting at 1 */
  1099.  
  1100.    This is even worse...
  1101.  
  1102. Again, why ? He decreased the pointers after assigning them,
  1103. now he's increasing them to get back the old values.
  1104.  
  1105.    program displays such a magnificent lack of understanding about C
  1106.    pointers that no quick fix should be attempted, despite the fact that
  1107.    a couple of quick changes will indeed fix this bit (though who knows
  1108.    about the rest of the program?)
  1109.  
  1110. Okay, I've hacked C for more than six years. I've done stuff not
  1111. unlike this myself, and it worked. Have I gotten my C all backward ?
  1112.  
  1113.    Not flaming anyone here; C pointers are tricky indeed...
  1114.  
  1115. Not especially, after the first two years or so...
  1116.  
  1117. Again, I quote you:
  1118.  
  1119.    already.  Go back to K&R, do not pass GO, an no $200.
  1120.  
  1121. Are you sure it's the original poster who should go back to K&R.
  1122. If he should, I should too, it seems.
  1123.  
  1124. - -- 
  1125. h+@nada.kth.se; Jon W{tte, the Diplomat - NOT!
  1126.  
  1127. +++++++++++++++++++++++++++
  1128.  
  1129. From: Pete Harlan <harlan@copper.ucs.indiana.edu>
  1130. Organization: Indiana University
  1131. Date: Wed, 8 Apr 1992 05:25:53 -0500
  1132.  
  1133. [Note: I followed up to this article once already in a totally idiotic
  1134. fashion, not having properly examined the code.  I cancelled it, but
  1135. if you read it please ignore it...]
  1136.  
  1137. In <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1138.  
  1139. |void allocateDATA (void)
  1140. |{
  1141. |    register i;
  1142.  
  1143. |    DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  1144. |    DATA -= 1;    /* to allow indexing starting at 1 */
  1145.  
  1146. |    for (i = 1; i <= NROW; i++){
  1147. |        DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  1148. |        DATA[i] -= 1;  /* to allow indexing starting at 1 */
  1149. |    }
  1150. |}
  1151.  
  1152. Okay, this is really pretty nifty, excepting for the fact, pointed out
  1153. by Steve Creps, that having a pointer to the 'element' before the
  1154. first element of an array might cause you problems (such as it
  1155. wrapping around to being a huge number, but even that might not cause
  1156. a problem).  (Actually, since NewPtr probably has some housekeeping
  1157. stuff before the actual allocated memory, as long as your element size
  1158. is small enough I'm sure you'll be okay.)
  1159.  
  1160. |However if I give the commands
  1161.  
  1162. |    allocateDATA();
  1163. |... heap size decreases
  1164. |    fillDATA();
  1165. |... which runs through the open file dialog, reads in a file and puts
  1166. |... the results into DATA, the heap size doesn't change ... which it's
  1167. |... not supposed to do since I've already allocated the memory.
  1168.  
  1169. |Now if I call
  1170. |    freeDATA();
  1171. |... and check the heap size it doesn't change ... it's as though I never
  1172. |... freed the data.
  1173.  
  1174.  
  1175. It would seem as if there's a problem with your fillDATA() routine.
  1176.  
  1177.  
  1178. Would it be possible, with real (e.g., not Think C) C++ to define a
  1179. class that is a 1-based array, and define the various operators on it
  1180. (e.g., [], dereferencing, +) so they would convert it back to 0-based,
  1181. and also define the casts to and from 0-based arrays, so that it would
  1182. be impossible to make a mistake when passing arrays to and from
  1183. routines that operate on 1-based arrays?  (The compiler would
  1184. automatically convert if a routine that was declared to take an object
  1185. of type 1-based-array were passed an ordinary C-based array, and
  1186. vice-versa.)
  1187.  
  1188. A friend has suggested doing this to interface code written to work
  1189. with 1-based X-Y coordinates with routines that expect 0-based
  1190. coordinates, and it seems that perhaps it could be beneficial here.
  1191.  
  1192. Of course, sticking to the C paradigm of 0-based arrays will not only
  1193. help your code work with more C code, but will also make it more
  1194. readable to others (such as simpletons like myself who didn't look at
  1195. it closely enough when you posted it).
  1196.  
  1197. - --Pete Harlan
  1198.   harlan@copper.ucs.indiana.edu
  1199.  
  1200. +++++++++++++++++++++++++++
  1201.  
  1202. From: erh0362@tesla.njit.edu
  1203. Date: 14 Apr 92 14:18:29 GMT
  1204. Organization: New Jersey Institute of Technology
  1205.  
  1206. > In <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1207. > |void allocateDATA (void)
  1208. > |{
  1209. > |    register i;
  1210. > |    DATA = (unsigned char **) NewPtr(NROW * sizeof(unsigned char *));
  1211. > |    DATA -= 1;    /* to allow indexing starting at 1 */
  1212. > |    for (i = 1; i <= NROW; i++){
  1213. > |        DATA[i] = (unsigned char *) NewPtr(NCOL * sizeof(unsigned char));
  1214. > |        DATA[i] -= 1;  /* to allow indexing starting at 1 */
  1215. > |    }
  1216. > |}
  1217. > Okay, this is really pretty nifty, excepting for the fact, pointed out
  1218. > by Steve Creps, that having a pointer to the 'element' before the
  1219. > first element of an array might cause you problems (such as it
  1220. > wrapping around to being a huge number, but even that might not cause
  1221. > a problem).  (Actually, since NewPtr probably has some housekeeping
  1222. > stuff before the actual allocated memory, as long as your element size
  1223. > is small enough I'm sure you'll be okay.)
  1224.  
  1225.  (various comments deleted )
  1226.  
  1227. > Would it be possible, with real (e.g., not Think C) C++ to define a
  1228. > class that is a 1-based array, and define the various operators on it
  1229. > (e.g., [], dereferencing, +) so they would convert it back to 0-based,
  1230. > and also define the casts to and from 0-based arrays, so that it would
  1231. > be impossible to make a mistake when passing arrays to and from
  1232. > routines that operate on 1-based arrays?  (The compiler would
  1233. > automatically convert if a routine that was declared to take an object
  1234. > of type 1-based-array were passed an ordinary C-based array, and
  1235. > vice-versa.)
  1236.  
  1237.     It's not only possible. It's a standard thing to do in certain 
  1238. circumstances. The trick that seems to be missed here is using two pointers 
  1239. instead of one. For instance to make an array of ints of dimension N that 
  1240. starts at index 1 do something like:
  1241.  
  1242.     int *temp, *myarray;
  1243.  
  1244.     temp = (int ) malloc(N * sizeof(int));
  1245.     myarray = temp - 1;
  1246.  
  1247. myarray now points to the element before temp. However you shouldn't actually 
  1248. dereference temp but instead use myarray[1] through myarray[N] to point to the 
  1249. appropriate elements. Using myarray[0] anywhere would cause untold havoc. This 
  1250. is all quite well documented in Numerical Recipes in C, along with routines to 
  1251. do similar things for multi-dimensional matrices.
  1252.  
  1253.  
  1254. Elliotte Rusty Harold        Department of Applied Mathematics
  1255. elharo@m.njit.edu        New Jersey Institute of Technology
  1256. erh0362@tesla.njit.edu        Newark, NJ 07103
  1257.  
  1258. +++++++++++++++++++++++++++
  1259.  
  1260. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  1261. Organization: Kalamazoo College
  1262. Date: Tue, 14 Apr 1992 15:30:34 GMT
  1263.  
  1264. erh0362@tesla.njit.edu writes:
  1265. >> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1266. >> 
  1267. >> |void allocateDATA (void)
  1268. >> |{
  1269. >> |    DATA -= 1;    /* to allow indexing starting at 1 */
  1270. >> |}
  1271. >> 
  1272. >> Okay, this is really pretty nifty, excepting for the fact, pointed out
  1273. >> by Steve Creps, that having a pointer to the 'element' before the
  1274. >> first element of an array might cause you problems...
  1275. >>
  1276. >> Would it be possible, with real (e.g., not Think C) C++ to define a
  1277. >> class that is a 1-based array
  1278. >
  1279. >    It's not only possible. It's a standard thing to do in certain 
  1280. >circumstances...
  1281. >
  1282. >    int *temp, *myarray;
  1283. >    temp = (int ) malloc(N * sizeof(int));
  1284. >    myarray = temp - 1;
  1285. >
  1286. >This is all quite well documented in Numerical Recipes in C,
  1287. >along with routines to do similar things for multi-dimensional matrices.
  1288.  
  1289. This will work on the Mac (currently), because pointers are always 32
  1290. bits, memory is contiguous, there's no memory protection, and everything
  1291. is generally clean and tidy.  But don't assume it's portable.  From the
  1292. comp.lang.c FAQ list:
  1293.  
  1294.  
  1295. 2.10:   Can I simulate a non-0-based array with a pointer?
  1296.  
  1297. A:      Not if the pointer points outside of the block of memory it is
  1298. intended to access, contrary to an idiom used in Numerical
  1299. Recipes in C.  If a pointer points outside of an allocated block
  1300. of memory, the behavior is undefined, _even if the pointer is
  1301. not dereferenced_.  (Explicit dispensation is granted, however,
  1302. for a pointer that points to the location one past an array's
  1303. last element.)
  1304.  
  1305. References: ANSI Rationale Sec. 3.2.2.3 p. 38.
  1306. [And see K&R 2nd ed. pp102-3 and 205 -- JRM]
  1307. - -- 
  1308.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  1309.  "Glass of milk / Standing in between extinction in the cold
  1310.   And explosive radiating growth" - They Might Be Giants
  1311.  
  1312. +++++++++++++++++++++++++++
  1313.  
  1314. From: karl@ima.isc.com (Karl Heuer)
  1315. Organization: Interactive Systems, Cambridge, MA 02138-5302
  1316. Date: Tue, 14 Apr 1992 19:29:35 GMT
  1317.  
  1318. In article <1992Apr14.091829.1@tesla.njit.edu> erh0362@tesla.njit.edu writes:
  1319. >>In <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1320. >>[Can you fake a 1-based array using C++ classes?]
  1321.  
  1322. Possibly, but I would avoid it if at all possible.
  1323.  
  1324. >[Use malloc()-1, as is done in Numerical Recipes]
  1325.  
  1326. It works in most cases on most architectures, but it's not legal C.
  1327. See question 2.10 of the FAQ.
  1328.  
  1329. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
  1330.  
  1331. +++++++++++++++++++++++++++
  1332.  
  1333. From: haney@moonshine.llnl.gov (Scott W. Haney)
  1334. Date: 14 Apr 92 22:11:59 GMT
  1335.  
  1336. karl@ima.isc.com (Karl Heuer) writes:
  1337.  
  1338. >In article <1992Apr14.091829.1@tesla.njit.edu> erh0362@tesla.njit.edu writes:
  1339. >>>In <1992Apr1.222646.10433@coe.montana.edu> umsfjban@bill.oscs.montana.edu (Jeff Banfield) writes:
  1340. >>>[Can you fake a 1-based array using C++ classes?]
  1341.  
  1342. >Possibly, but I would avoid it if at all possible.
  1343.  
  1344. Why avoid it? One can easily (well, relatively easily) construct portable, 
  1345. vectorizable matrix and vector classes using C++.  
  1346. I've done it as have a number of other people (see the recent discussion on 
  1347. comp.lang.c++).  There is no kludging involved and it it is much easier to 
  1348. deal with 1-based arrays stored by columns since most of the scientific
  1349. world still is based on Fortran.
  1350.  
  1351. Scott
  1352. - --
  1353. - -------------------------------------------------------------------------
  1354. Scott W. Haney        || Lawrence Livermore N'Lab || The above views are 
  1355. haney@random.llnl.gov || P.O. Box 808;  L-644     || mine and not neces-
  1356. (510) 423-6308        || Livermore, CA  94550     || sarily LLNL's.
  1357.  
  1358. +++++++++++++++++++++++++++
  1359.  
  1360. From: atbowler@thinkage.on.ca (Alan Bowler)
  1361. Date: 15 Apr 92 17:10:13 GMT
  1362. Organization: /etc/organization
  1363.  
  1364. In article <1992Apr14.153034.18214@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  1365. >erh0362@tesla.njit.edu writes:
  1366. >>
  1367. >>    It's not only possible. It's a standard thing to do in certain 
  1368. >>circumstances...
  1369. >>
  1370. >>    int *temp, *myarray;
  1371. >>    temp = (int ) malloc(N * sizeof(int));
  1372. >>    myarray = temp - 1;
  1373. >>
  1374. >>This is all quite well documented in Numerical Recipes in C,
  1375. >>along with routines to do similar things for multi-dimensional matrices.
  1376. >
  1377. >This will work on the Mac (currently), because pointers are always 32
  1378. >bits, memory is contiguous, there's no memory protection, and everything
  1379. >is generally clean and tidy.  But don't assume it's portable.  
  1380.  
  1381. It is true that this use of pointers is not sanctioned by the the
  1382. standard.  As the FAQ points out there may exist architectures and
  1383. implementations where
  1384.     p = &array[0] - 1;
  1385. might not give a useable pointer, so p[1] will not address array[0].
  1386.  
  1387. However, these machines are not all that common, and it may be
  1388. legitimate to say that you are not interested in porting to them.
  1389. "portability" is NOT an absolute value.  It is a measure of how
  1390. much effort it is to reuse the existing code versus how much effort
  1391. to reimplement from scratch.  It is affected by features of the new
  1392. environment.  No program is absolutely portable to all environments.
  1393. (As a trivial example, by choosing a language, you restrict the code
  1394. to environments that support that language.)  Any program has a set of
  1395. enviroments that it is easily ported to, and as a rule of thumb you
  1396. should strive to make that set as large as possible.  However, there
  1397. are tradeoffs, and the larger the set of environments, the more time
  1398. and effort goes into the programming and maintenance.  It may well be
  1399. a smart decision to decide that you are not interested in porting to
  1400. certain environments.  As an extreme case, if you are writing a
  1401. compiler to produce code for a sewing machine, you probably are not
  1402. worried about making the compiler itself run on the sewing machine,
  1403. and so don't need to worry about the fact that there is no file system.
  1404. A harder choice would be a compiler for a 36/72 bit machine.  Is it
  1405. worth worrying about making it run as a cross compiler from a 32 bit
  1406. workstation.  There would be would be a lot of overhead in writing
  1407. routines to simulate the target machine arithmetic, and using routines
  1408. instead of inline operators would have a performance penalty when
  1409. running the compiler on the 36/72 bit machine.  The tradeoffs are not
  1410. clear.
  1411.  
  1412. Certainly there are a number of coding practices that cost very little
  1413. and widen the set of target machines.  These should be used routinely.
  1414. However, portability is not the only goal, and you need to consider the
  1415. tradeoffs of wider portability versus the costs in extra code poorer
  1416. performance etc.
  1417.  
  1418.  
  1419. ---------------------------
  1420.  
  1421. End of C.S.M.P. Digest
  1422. **********************
  1423.